// AOP 实现职责链
Function.prototype.after = function (fn) {
    let self = this;
    return function () {
        let ret = self.apply(this, arguments);
        if (ret === 'nextSuccessor') {
            return fn.apply(this, arguments);
        }
        return ret;
    }
}

const supportFlash = function() {
    let swf = typeof window.ActiveXObject !== "undefined"
        ? new ActiveXObject('ShockwaveFlash.ShockwaveFlash')
        : navigator.plugins['Shockwave Flash'];
    return swf ? true : false;
}

// 用职责链实现获取文件上传对象的例子
const getActiveUploadObj = function() {
    try {
        return new ActiveXObject("TXFTNActiveX.FTNUpload"); // IE 上传控件
    } catch (error) {
        return 'nextSuccessor';
    }
}

const getFlashUploadObj = function() {
    if (supportFlash()) {
        let str = '<object type="application/x-shockwave-flash"></object>';
        return $(str).appendTo($('body'));
    }
    return 'nextSuccessor';
}

const getFormUpladObj = function() {
    return $('<form><input name="file" type="file"/></form>').appendTo($('body'));
}

let getUploadObj = getActiveUploadObj.after(getFlashUploadObj).after(getFormUpladObj);
console.log(getUploadObj());
